package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class JDBCDemo5 {
    public static void main(String[] args) {
        //关联查询

        try(
                Connection connection=DBUtil.getConnection();
                ){
            Statement statement =connection.createStatement();
            String sql="SELECT t.name,t.salary,t.title,c.name,c.floor " +
                    "FROM teacher t " +
                    "JOIN class  c ON t.id=c.teacher_id " +
                    "WHERE t.name= '王克晶' ";
            System.out.println(sql);
            ResultSet rs=statement.executeQuery(sql);
            while (rs.next()){
                /*String tname =rs.getString("t.name");
                int salary=rs.getInt("t.salary");
                String title=rs.getString("t.title");
                String cname=rs.getString("c.name");
                int floor=rs.getInt("c.floor");*/

                //索引从1开始 可以按照索引来获取
                String tname =rs.getString(1);
                int salary=rs.getInt(2);
                String title=rs.getString(3);
                String cname=rs.getString(4);
                int floor=rs.getInt(5);
                System.out.println(tname+" "+salary+" "+title+" "+cname+" "+floor);
            }



        }catch (Exception e){
            e.printStackTrace();
        }



    }
}
